package com.atguigu.service.Impl;

import com.atguigu.dao.BaseDao;
import com.atguigu.dao.RolePermissionDao;
import com.atguigu.entity.RolePermission;
import com.atguigu.service.RolePermissionService;
import com.atguigu.service.RoleService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @title：
 * @author：Yu
 * @create：2023-03-01 11:17
 * @description：
 */
@DubboService
public class RolePermissionServiceImpl extends BaseServiceImpl<RolePermission> implements RolePermissionService {
    @Autowired
    private RolePermissionDao rolePermissionDao;

    @Override
    public BaseDao<RolePermission> getBaseDao() {
        return rolePermissionDao;
    }

    @Override
    @Transactional
    public void insertDate(Long roleId, String[] permissionIds) {
        //1.删除该用户所有的权限
        rolePermissionDao.deleteByRoleId(roleId);
        //2.添加该用户所具有和新增的权限
        for (String permissionId : permissionIds) {
            if (permissionId.equals("")) {
                continue;
            }
            RolePermission rolePermission = new RolePermission();
            rolePermission.setRoleId(roleId);
            rolePermission.setPermissionId(Long.valueOf(permissionId));
            rolePermissionDao.insert(rolePermission);
        }
    }
}
